#!/usr/bin/python

import sys
import optparse

def read_map(fname):
    return dict((gene_id, gene_int) for (gene_int,gene_id) in (line.split() for line in open(fname)))

def main(options):
    #genes_map = read_map(options.genes_map)
    genomes_map = read_map(options.genomes_map)
    for line in sys.stdin:
        gene_id, genom_id = line.split()
        sys.stdout.write("%s\t%s\n" % (gene_id, genomes_map[genom_id]))


if __name__ == "__main__":
    import gc
    gc.disable()

    parser = optparse.OptionParser(
        usage = 'cat results | %prog --gene-map GENES_MAP_FILE --genom-map GENOMES_MAP_FILE',
    )
    parser.add_option(
        '--genes-map',
        dest = 'genes_map',
    )
    parser.add_option(
        '--genomes-map',
        dest = 'genomes_map',
    )
    options, args = parser.parse_args()

    main(options)

